/* typehints:start */
import { Npc } from "../npcs/npc";
import { GameRoot } from "../root";
/* typehints:end */

import { createLogger } from "../../core/utils/logging";
import MapSiteModules from './get_map_site'

const logger = createLogger('maps/map_clip')

/**
 * 创建一个世界地图块
 */
export class MapClip{
  constructor(root, title, pos){
    this.title = title;
    this.pos = pos || [0, 0];

    /** @type {GameRoot} */
    this.root = root;

    this.map = {};
  }

  add(data){
    if(this.map[data.mapPos]) {
      logger.error('地图错误信息: 世界定位: ', this.title, this.pos, '地图定位: ', data.mapPos);
      assert(false, '地图编写错误，重复的定位');
      return;
    }

    assert(MapSiteModules[data.key], '地图区域不存在')

    this.map[data.mapPos] = (new MapSiteModules[data.key](this.root)).set(data.mapPos, data.attr);
  }

  onEnter(){
    this.root.worldMap.createItem(this.pos);
  }

  onLeave(){
    
  }
}